# config_loader.py
import os
from dotenv import load_dotenv
from pathlib import Path


def load_config():
    # 获取当前文件的绝对路径
    current_dir = Path(__file__).parent

    # 构建 .env 文件的路径
    env_path = current_dir.parent.parent / 'config'
    # print(env_path)
    # 先加载通用的环境变量
    load_dotenv(env_path / '.env')
    # 首先获取当前的环境状态（记录在.gitlab-ci.yml中）如果获取不到则默认使用dev开发环境
    # env_state = os.getenv("ENV_STATE", "pro")
    # env_state = os.getenv("ENV_STATE", "")
    env_state = os.getenv("ENV_STATE", "dev")
    # 加载特定环境的环境变量
    env_file_path = env_path / f'.env.{env_state}'
    # print(env_file_path)
    if env_file_path.exists():
        load_dotenv(env_file_path, override=True)
    else:
        print(f"Warning: Environment file '{env_file_path}' not found. Using default environment variables.")

